package com.yanqu.road.server.cmd.activity.lanyamemorial;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LangYaMemorialProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.langyamemorial.LangYaMemorialModule;
import com.yanqu.road.server.manger.activity.langyamemorial.LangYaMemorialMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_LANGYA_MEMORIAL_ALL_CONTRIBUTION_SYNC_FROM_CROSS, desc = "全服进度同步")
public class LangYaMemorialSyncAllFromCross implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        LangYaMemorialProto.CrossLangYaMemorialSyncAllBuildValueMsg sync = LangYaMemorialProto.CrossLangYaMemorialSyncAllBuildValueMsg.parseFrom(yanQuMessage.getBytes());

        LangYaMemorialMgr.getCacheAllBuildValueMap().put(sync.getActivityId(), sync.getBuildValue());

        for (GamePlayer player : GamePlayerMgr.getCopyPlayerList()) {
            player.getModule(LangYaMemorialModule.class).updateAllBuildValue(sync.getActivityId(), sync.getBuildValue());
        }
    }
}
